from commons.entity.po.reimbursement import Reimbursement
from commons.entity.po.user import User

from commons.entity.po.model import db


class ReimbursementApprovalMa(db.Model):
    __tablename__ = 'reimbursement_approval_ma'

    reimbursement_approval_ma_id = db.Column(db.Integer, primary_key=True, autoincrement=True,
                                             info='经理审批报销申请编号')
    reimbursement_id = db.Column(db.ForeignKey(
        'reimbursement.reimbursement_id'), index=True, info='报销编号')
    manager_id = db.Column(db.ForeignKey(
        'user.user_id'), index=True, info='经理编号')
    date = db.Column(db.Date, info='审批日期')

    manager = db.relationship('User', primaryjoin='ReimbursementApprovalMa.manager_id == User.user_id',
                              backref='reimbursement_approval_mas')
    reimbursement = db.relationship('Reimbursement',
                                    primaryjoin='ReimbursementApprovalMa.reimbursement_id == '
                                                'Reimbursement.reimbursement_id',
                                    backref='reimbursement_approval_mas')

    def to_dict(self):
        return {
            'reimbursement_approval_ma_id': self.reimbursement_approval_ma_id,
            'reimbursement_id': self.reimbursement_id,
            'manager_id': self.manager_id,
            'date': self.date.isoformat() if self.date else None
        }

    def to_dict_2(self):
        return {
            'reimbursementApprovalMaId': self.reimbursement_approval_ma_id,
            'reimbursementId': self.reimbursement_id,
            'managerId': self.manager_id,
            'date': self.date.isoformat() if self.date else None
        }
